const axios = require('axios');

const api = {};

api.info = function (option) {
    axios.get('/api/store/info.ajax').then(function (response) {
        if(response.data.error === 0){
            if('success' in option)
                option.success(response.data.data);
        } else {
            if('fail' in option)
                option.fail(response.data.message);
        }
    }).catch(function (error) {
        if('error' in option)
            option.error(error);
    });
};

/**
 * 创建商品接口
 * @param data
 * @param option
 */
api.update = function (data, option) {
    let params = new URLSearchParams;
    for(let x in data) params.append(x,data[x]);
    axios.post('/api/store/update.do',params).then(function (response) {
        if(response.data.error === 0){
            if('success' in option)
                option.success(response.data.data);
        } else {
            if('fail' in option)
                option.fail(response.data.message);
        }
        if('complete' in option)
            option.complete();
    }).catch(function (error) {
        if('error' in option)
            option.error(error);
        if('complete' in option)
            option.complete();
    });
};

export default api;